from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-04-01 14:11:24.244958
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 01, Apr, 2021
Time: 14:11:28
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.2653
Nobs: 248.000 HQIC: -48.0270
Log likelihood: 2941.93 FPE: 8.30594e-22
AIC: -48.5403 Det(Omega_mle): 5.81938e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.449556 0.127514 3.526 0.000
L1.Burgenland 0.070779 0.063082 1.122 0.262
L1.Kärnten -0.217843 0.054434 -4.002 0.000
L1.Niederösterreich 0.082692 0.140217 0.590 0.555
L1.Oberösterreich 0.220291 0.130403 1.689 0.091
L1.Salzburg 0.265772 0.070716 3.758 0.000
L1.Steiermark 0.136572 0.091213 1.497 0.134
L1.Tirol 0.114379 0.061980 1.845 0.065
L1.Vorarlberg -0.030319 0.057267 -0.529 0.597
L1.Wien -0.078483 0.117570 -0.668 0.504
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.482927 0.152241 3.172 0.002
L1.Burgenland 0.005074 0.075314 0.067 0.946
L1.Kärnten 0.336911 0.064990 5.184 0.000
L1.Niederösterreich 0.107783 0.167406 0.644 0.520
L1.Oberösterreich -0.079109 0.155689 -0.508 0.611
L1.Salzburg 0.212934 0.084429 2.522 0.012
L1.Steiermark 0.118061 0.108900 1.084 0.278
L1.Tirol 0.137424 0.073998 1.857 0.063
L1.Vorarlberg 0.157124 0.068372 2.298 0.022
L1.Wien -0.466399 0.140368 -3.323 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.297350 0.062253 4.777 0.000
L1.Burgenland 0.098065 0.030797 3.184 0.001
L1.Kärnten -0.014608 0.026575 -0.550 0.583
L1.Niederösterreich 0.051682 0.068454 0.755 0.450
L1.Oberösterreich 0.284694 0.063663 4.472 0.000
L1.Salzburg 0.017841 0.034524 0.517 0.605
L1.Steiermark 0.022176 0.044530 0.498 0.618
L1.Tirol 0.066530 0.030259 2.199 0.028
L1.Vorarlberg 0.083258 0.027958 2.978 0.003
L1.Wien 0.098326 0.057398 1.713 0.087
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.216136 0.063588 3.399 0.001
L1.Burgenland 0.020753 0.031457 0.660 0.509
L1.Kärnten 0.008088 0.027145 0.298 0.766
L1.Niederösterreich 0.046881 0.069922 0.670 0.503
L1.Oberösterreich 0.403067 0.065028 6.198 0.000
L1.Salzburg 0.081809 0.035264 2.320 0.020
L1.Steiermark 0.133431 0.045485 2.934 0.003
L1.Tirol 0.048866 0.030907 1.581 0.114
L1.Vorarlberg 0.082588 0.028557 2.892 0.004
L1.Wien -0.041390 0.058629 -0.706 0.480
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.512171 0.124522 4.113 0.000
L1.Burgenland 0.083525 0.061602 1.356 0.175
L1.Kärnten 0.010946 0.053157 0.206 0.837
L1.Niederösterreich -0.027980 0.136927 -0.204 0.838
L1.Oberösterreich 0.133408 0.127343 1.048 0.295
L1.Salzburg 0.056601 0.069057 0.820 0.412
L1.Steiermark 0.092973 0.089072 1.044 0.297
L1.Tirol 0.211349 0.060525 3.492 0.000
L1.Vorarlberg 0.030213 0.055923 0.540 0.589
L1.Wien -0.094460 0.114811 -0.823 0.411
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.188169 0.096945 1.941 0.052
L1.Burgenland -0.013725 0.047959 -0.286 0.775
L1.Kärnten -0.015666 0.041385 -0.379 0.705
L1.Niederösterreich -0.024474 0.106603 -0.230 0.818
L1.Oberösterreich 0.417066 0.099141 4.207 0.000
L1.Salzburg 0.010867 0.053763 0.202 0.840
L1.Steiermark -0.004652 0.069346 -0.067 0.947
L1.Tirol 0.157696 0.047121 3.347 0.001
L1.Vorarlberg 0.057629 0.043538 1.324 0.186
L1.Wien 0.232095 0.089385 2.597 0.009
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.248762 0.120088 2.071 0.038
L1.Burgenland 0.018614 0.059408 0.313 0.754
L1.Kärnten -0.063791 0.051264 -1.244 0.213
L1.Niederösterreich -0.060399 0.132051 -0.457 0.647
L1.Oberösterreich 0.013908 0.122808 0.113 0.910
L1.Salzburg 0.076320 0.066598 1.146 0.252
L1.Steiermark 0.337302 0.085901 3.927 0.000
L1.Tirol 0.456730 0.058370 7.825 0.000
L1.Vorarlberg 0.149348 0.053932 2.769 0.006
L1.Wien -0.171471 0.110723 -1.549 0.121
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.138405 0.141690 0.977 0.329
L1.Burgenland 0.050502 0.070095 0.720 0.471
L1.Kärnten -0.070431 0.060486 -1.164 0.244
L1.Niederösterreich 0.195654 0.155805 1.256 0.209
L1.Oberösterreich -0.006790 0.144900 -0.047 0.963
L1.Salzburg 0.203741 0.078578 2.593 0.010
L1.Steiermark 0.117305 0.101353 1.157 0.247
L1.Tirol 0.056044 0.068870 0.814 0.416
L1.Vorarlberg 0.100534 0.063633 1.580 0.114
L1.Wien 0.218996 0.130641 1.676 0.094
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.589832 0.076985 7.662 0.000
L1.Burgenland -0.040196 0.038085 -1.055 0.291
L1.Kärnten -0.025562 0.032864 -0.778 0.437
L1.Niederösterreich 0.011770 0.084653 0.139 0.889
L1.Oberösterreich 0.329669 0.078728 4.187 0.000
L1.Salzburg 0.018839 0.042694 0.441 0.659
L1.Steiermark -0.031234 0.055068 -0.567 0.571
L1.Tirol 0.087687 0.037419 2.343 0.019
L1.Vorarlberg 0.111147 0.034574 3.215 0.001
L1.Wien -0.043598 0.070981 -0.614 0.539
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.139763 0.037904 0.161382 0.218162 0.059436 0.077302 -0.004657 0.153156
Kärnten 0.139763 1.000000 0.016853 0.205895 0.178366 -0.067069 0.159876 0.021735 0.307489
Niederösterreich 0.037904 0.016853 1.000000 0.247748 0.070613 0.301570 0.138585 0.029605 0.303847
Oberösterreich 0.161382 0.205895 0.247748 1.000000 0.300899 0.276748 0.088508 0.060589 0.136370
Salzburg 0.218162 0.178366 0.070613 0.300899 1.000000 0.157887 0.048387 0.089497 -0.001364
Steiermark 0.059436 -0.067069 0.301570 0.276748 0.157887 1.000000 0.109630 0.094348 -0.124296
Tirol 0.077302 0.159876 0.138585 0.088508 0.048387 0.109630 1.000000 0.163477 0.144792
Vorarlberg -0.004657 0.021735 0.029605 0.060589 0.089497 0.094348 0.163477 1.000000 0.001465
Wien 0.153156 0.307489 0.303847 0.136370 -0.001364 -0.124296 0.144792 0.001465 1.000000